package com.example.sprintboot.controller;

import com.example.sprintboot.common.Result;
import com.example.sprintboot.entity.Cart;
import com.example.sprintboot.service.CartService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;

    // 查所有数据
    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Cart> list = cartService.selectAll();
        return Result.success(list);
    }

    // 查单个数据
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Cart cart = cartService.selectById(id);
        return Result.success(cart);
    }

    // 新增数据
    @PostMapping("/add")
    public Result add(@RequestBody Cart cart) {
        cartService.add(cart);
        return Result.success();
    }

    // 更新数据
    @PutMapping("/update")
    public Result update(@RequestBody Cart cart) {
        cartService.update(cart);
        return Result.success();
    }

    // 删除数据
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        cartService.deleteById(id);
        return Result.success();
    }
}